<table width="100%"><tr><td width="20%">
<a href="../index.html">&lt; index</a><br />
<a href="index.html">&lt; 2. Console</a><br />
<a href="console_drawing.html">&lt; 2.2 Drawing on the root console</a>
</td><td width="60%">
<p align="center">
=====================================<br />
Printing a centered string with autowrap<br />
=====================================<br />
</p></td><td width="20%">
</td></tr></table>
<style type="text/css">
.code { color:#444444; background-color:#EEEEEE;}
pre { color:#444444; background-color:#EEEEEE;}
table.param td { border : 1px solid #000000; }
th { background-color: #44BBFF; color: #FFFFFF }
table.none td { border : 0 }
</style>
<p class="code"><pre>
C++ : int TCODConsole::printCenterRect(int x, int y, int w, int h, TCOD_bkgnd_flag_t flag, const char *fmt, ...)
C   : int TCOD_console_print_center_rect(TCOD_console_t con,int x, int y, int w, int h, TCOD_bkgnd_flag_t flag, const char *fmt, ...)
Py  : console_print_center_rect(con,x, y, w, h, flag, fmt)
</pre></p>
This function draws a centered string in a rectangle inside the console, using default foreground and background colors. If the string reaches the borders of the rectangle, carriage returns are inserted.<br />
If h > 0 and the bottom of the rectangle is reached, the string is truncated. If h = 0, the string is only truncated if it reaches the bottom of the console.<br/>
The function returns the height (number of console lines) of the printed string.<br />
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>con</td><td>In the C version, the offscreen console handler or NULL for the root console.</td></tr>
<tr><td>x,y</td><td>Coordinates of the rectangle's top middle position in the console.<br />0 &lt;= x &lt; console width<br />0 &lt;= y &lt; console height</td></tr>
<tr><td>w,h</td><td>Size of the rectangle in the console.<br />0 &lt;= x-w/2 &lt;= x+w/2 &lt; console width<br />y &lt;= y+h &lt; console height</td></tr>
<tr><td>flag</td><td>This flag defines how the cell's background color is modified. See <a href="bkgnd_flag.html">TCOD_bkgnd_flag_t</a>.</td></tr>
<tr><td>fmt</td><td>printf-like format string, eventually followed by parameters. You can use <a href="console_color_control.html">control codes</a> to change the colors inside the string.</td></tr>
</table>
<br />
You can also get the expected height without actually printing the string :
<p class="code"><pre>
C++ : int TCODConsole::getHeightCenterRect(int x, int y, int w, int h, const char *fmt, ...)
C   : int TCOD_console_height_center_rect(TCOD_console_t con,int x, int y, int w, int h, const char *fmt, ...)
Py  : console_height_center_rect(con,x, y, w, h, fmt)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>con</td><td>In the C version, the offscreen console handler or NULL for the root console.</td></tr>
<tr><td>x,y</td><td>Coordinates of the rectangle's top middle position in the console.<br />0 &lt;= x &lt; console width<br />0 &lt;= y &lt; console height</td></tr>
<tr><td>w,h</td><td>Size of the rectangle in the console.<br />0 &lt;= x-w/2 &lt;= x+w/2 &lt; console width<br />y &lt;= y+h &lt; console height</td></tr>
<tr><td>fmt</td><td>printf-like format string, eventually followed by parameters. You can use <a href="console_color_control.html">control codes</a> to change the colors inside the string.</td></tr>
</table>

